<template>
  <div>
    <el-form label-width="80px">
      <el-form-item label="用户名" prop="username">
        <el-input v-model="form.username"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input type="password" v-model="form.password"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="login">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script setup>
import { reactive, toRefs } from "vue";
import http from "@/utils/http";
import { ElMessage } from "element-plus";
import { useRouter } from 'vue-router'
const router = useRouter()
const Data = reactive({
  form: {
    username: "",
    password: "",
  },
});
const { form } = toRefs(Data);
const login = () => {
  http
    .post("/user/ua/login", {
      userName: Data.form.username,
      password: Data.form.password,
    })
    .then((res) => {
      if(res.data.access_token){
        localStorage.setItem("access_token", res.data.access_token);
        router.push("/home/areaList");
      }else{
        ElMessage.error(res.data.msg);
      }
    })
    .catch((err) => {
      console.log(err);
    });
};
</script>
<style>
</style>